package com.mindskip.xzs.controller.student;

import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.context.WebContext;
import com.mindskip.xzs.domain.dto.student.exampaper.ExamPaperPageDTO;
import com.mindskip.xzs.domain.vo.admin.exampaper.ExamPaperWithQuestionVO;
import com.mindskip.xzs.domain.vo.student.exampaper.ExamPaperPageVO;
import com.mindskip.xzs.service.ExamPaperService;
import com.mindskip.xzs.utility.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController("StudentExamPaperController")
@RequestMapping(value = "/api/student/exam/paper")
public class ExamPaperController {

    private final ExamPaperService examPaperService;

    private final WebContext webContext;

    public ExamPaperController(ExamPaperService examPaperService, WebContext webContext) {
        this.examPaperService = examPaperService;
        this.webContext = webContext;
    }

    @PostMapping("/pageList")
    public RestResponse<PageInfo<ExamPaperPageVO>> page(@RequestBody @Valid ExamPaperPageDTO examPaperPageDTO) {

        examPaperPageDTO.setLevelId(webContext.getCurrentUser().getUserLevel());
        PageInfo<ExamPaperPageVO> examPaperByPageStudent = examPaperService.getExamPaperByPageStudent(examPaperPageDTO);
        return RestResponse.ok(examPaperByPageStudent);
    }

    @PostMapping("/select/{id}")
    public RestResponse<ExamPaperWithQuestionVO> select(@PathVariable Integer id) {
        ExamPaperWithQuestionVO examPaperWithQuestion = examPaperService.getExamPaperWithQuestion(id);
        return RestResponse.ok(examPaperWithQuestion);
    }
}
